public class MyBlockingqueue {
    String[] arr=new String[20];
    private volatile int head=0;
    private volatile int end=0;
    private volatile int size=0;
    public void put(String elem) throws InterruptedException {
        synchronized (this){
            if(end==arr.length){
                this.wait();
                return;
            }
            arr[end]=elem;
            end++;
            size++;
            this.notify();
            if(end==arr.length){
                end=0;
            }
        }

    }
    public String tack() throws InterruptedException {
        synchronized (this){
            if (size==0){
                this.wait();
            }
            String ret=arr[head];
            head++;
            size--;
            this.notify();
            if(head==arr.length){
                head=0;
            }
            return ret;
        }
    }

}
